var STATE_ERROR=-1;
var STATE_UNINITIATED=0;
var STATE_LOADING=1;
var STATE_LOADED=2;
var STATE_INTERACTIVE=3;
var STATE_COMPLETE=4;

if (typeof(__AJAXB)!='boolean')
{
  var __AJAXB=true;
  
  var __AJAX={
  
    conn : new XMLHttpRequest(),
    __lastError : '',
    
    HEAD : function(url)
    {
      var RetVal=false;
      __AJAX.__lastError='';

      if(__AJAX.getState()!=STATE_ERROR)
      {
        __AJAX.conn.open('HEAD', url, false); 
        try
        {
          __AJAX.conn.send(null);
          RetVal=true;
        }
        catch(ex)
        {
          __AJAX.__lastError='Error connecting to server';
        };
      }

      return(RetVal);
    },
    
    GET : function(url,queryString,poxhttp)
    {
      var RetVal=false;
      var newUrl=url+'?'+queryString;
      
      __AJAX.__lastError='';

      if(__AJAX.getState()!=STATE_ERROR)
      {
        __AJAX.conn.open('GET', newUrl, false); 

        if(poxhttp)
        {
          __AJAX.conn.setRequestHeader('Accept','application/xml');
          __AJAX.conn.setRequestHeader('Content-Type','application/xml');
        }

        try
        {
          __AJAX.conn.send(null);
          RetVal=true;
        }
        catch(ex)
        {
          __AJAX.__lastError='Error connecting to server';
        };
      }

      return(RetVal);
    },
    
    POST : function(url,postData,poxhttp)
    {
      var RetVal=false;
      
      __AJAX.__lastError='';

      if(__AJAX.getState()!=STATE_ERROR)
      {
        __AJAX.conn.open('POST', url, false); 

        if(poxhttp)
        {
          __AJAX.conn.setRequestHeader('Accept','application/xml');
          __AJAX.conn.setRequestHeader('Content-Type','application/xml');
        }

        try
        {
          __AJAX.conn.send(postData);
          RetVal=true;
        }
        catch(ex)
        {
          __AJAX.__lastError='Error connecting to server';
        };
      }

      return(RetVal);
    },
    
    getLastError : function()
    {
      return(__AJAX.__lastError);
    },

    getState : function()
    {
      var RetVal=STATE_ERROR;
      __AJAX.__lastError='';

      if(__AJAX.conn!=null)
        RetVal=__AJAX.conn.readyState;
      else
        __AJAX.__lastError='Connection not initialized';
      
      return(RetVal);
    },
  
    getStatusCode : function()
    {
      var RetVal=-1;
      __AJAX.__lastError='';

      if(__AJAX.getState()==STATE_COMPLETE)
        RetVal=__AJAX.conn.status;
      else
        __AJAX.__lastError='Connection not complete';
      
      return(RetVal);
    },
    
    getStatusText : function()
    {
      var RetVal='';
      __AJAX.__lastError='';

      if(__AJAX.getState()==STATE_COMPLETE)
        RetVal=__AJAX.conn.statusText;
      else
        __AJAX.__lastError='Connection not complete';
      
      return(RetVal);
    },
    
    getResponseXML : function()
    {
      var RetVal=null;
      __AJAX.__lastError='';

      if(__AJAX.getState()==STATE_COMPLETE)
        RetVal=__AJAX.conn.responseXML;
      else
        __AJAX.__lastError='Connection not complete';
      
      return(RetVal);
    },
    
    getResponseHeader : function(headerName)
    {
      var RetVal=null;
      __AJAX.__lastError='';

      if(__AJAX.getState()==STATE_COMPLETE)
        RetVal=__AJAX.conn.getResponseHeader(headerName);
      else
        __AJAX.__lastError='Connection not complete';
      
      return(RetVal);
    },

    getResponseHeaders : function()
    {
      var RetVal=null;
      __AJAX.__lastError='';

      if(__AJAX.getState()==STATE_COMPLETE)
        RetVal=__AJAX.conn.getAllResponseHeaders();
      else
        __AJAX.__lastError='Connection not complete';
      
      return(RetVal);
    },

    getResponseText : function()
    {
      var RetVal=null;
      __AJAX.__lastError='';

      if(__AJAX.getState()==STATE_COMPLETE)
        RetVal=__AJAX.conn.responseText;
      else
        __AJAX.__lastError='Connection not complete';
      
      return(RetVal);
    }
    
  }
}